#include "wingplane.h"

WingPlane::WingPlane()
{

    //加载飞机图片
    m_Wing_Plane.load(WING_PATH1);
    //初始化飞机坐标
    m_x=(GAME_WIDTH-m_Wing_Plane.width())*0.5;
    m_y=(GAME_HEIGHT-m_Wing_Plane.height()+100);
    //初始化边框
    m_Rect.setWidth(m_Wing_Plane.width()-100);
    m_Rect.setHeight(m_Wing_Plane.height()-10);
    m_Rect.moveTo(m_x+50,m_y+5);
    //初始化伤害
    m_Hurt=WING_BULLET01_HURT;

    //僚机子弹
    for(int i=0;i<WING_BULLET_NUM;i++)
    {
        m_bullets[i].m_Bullet.load(":/rec.image/Wing_bullet01.png");
    }
    //僚机状态
    is_on=0;
}

void WingPlane::shoot()
{
    if(is_on)
    {
        //累加时间间隔
        m_Recorder++;
        //如果记录的数字未达到发射子弹的时间间隔，不发射子弹
        if(m_Recorder<WING_BULLLET_INTERVAL)
        {
            return;
        }
        //达到发射时间
        m_Recorder=0;
        //发射一行子弹

        for(int i=0;i<WING_BULLET_NUM;i++)
        {

            //如果是空闲子弹 进行发射
            if(m_bullets[i].m_Free)
            {
                //发射
                m_bullets[i].m_Free=0;
                //设置子弹坐标
                m_bullets[i].m_x=m_x;
                m_bullets[i].m_y=m_y-40;
                break;
            }
        }
    }
}

void WingPlane::setPOsition(int x, int y)
{
    if(is_on)
    {
        m_x=x;
        m_y=y;
        m_Rect.moveTo(m_x+50,m_y+5);
    }
}
